package lxm.demo.ultra;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;
import in.srain.cube.views.ptr.header.StoreHouseHeader;
import lxm.demo.ultra.utils.PixelUtils;


public class StoreHouseHeaderFragment extends Fragment {

    Unbinder unbinder;
    @BindView(R2.id.ptr_store_hose_layout)
    PtrFrameLayout ptrStoreHoseLayout;


    public static StoreHouseHeaderFragment getInstance() {
        StoreHouseHeaderFragment fragment = new StoreHouseHeaderFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_store_hose, container, false);
        unbinder = ButterKnife.bind(this, view);
        StoreHouseHeader storeHeader = new StoreHouseHeader(getContext());
        storeHeader.setPadding(0, PixelUtils.dip2px(getContext(), 15), 0, 0);
//        storeHeader.initWithString("Alibaba");
        storeHeader.initWithStringArray(R.array.storehouse);
        ptrStoreHoseLayout.setDurationToCloseHeader(1500);
        ptrStoreHoseLayout.setHeaderView(storeHeader);
        ptrStoreHoseLayout.addPtrUIHandler(storeHeader);
        ptrStoreHoseLayout.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return true;
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                ptrStoreHoseLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
//                ptrStoreHoseLayout.autoRefresh(false);
                        ptrStoreHoseLayout.refreshComplete();
                    }
                }, 1000);
            }
        });

        return view;

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

}
